#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <pthread.h>

#include "quicklz.h"

#include "rgb2color.h"
#include "PNGdec.h"
#include "soft_dev.h"



int main(int argc, char ** argv){
	
	static PNGIMAGE png;
	bool tFlage;
	uint8_t uid;
	spi_host_device_t host_spi;
	virt_dev_drv *draw_device = virt_create_dev(host_spi, 0, DEFAULT_COLOR);
	char filename[64] = { 0 };
	if(argc != 2)
		uid = 1;
	else
		uid = atoi(argv[1]);

	char *cPath=getcwd(NULL, 0);
	sprintf(filename, "%s/png/doc/%d.png", cPath, uid);

	int ret = PNG_openFile(&png, filename, png_draw_callback);
	if( 0 != ret){
		printf("open %s file ret:%x fail... \n\r", filename, ret);
		return -1;
	}
	printf("    Width: %03d      Height: %03d \n", png.iWidth, png.iHeight);
	printf("    Bit depth: %u    Color Type: %u    Interlace method: %d \n",
			png.ucBpp, png.ucPixelType, png.iInterlaced);
	printf("    Number of bytes per line: %d \n", png.iPitch);
	
	draw_device->disp_mode = 0x10;
	draw_device->drv->cmd(draw_device->dev, 0x10);
	ret = DecodePNG(&png, (void*)draw_device, 0);

	draw_device->disp_mode = 0x13;
	draw_device->drv->cmd(draw_device->dev, 0x13);
	DecodePNG(&png, (void*)draw_device, 0);
	draw_device->drv->refresh(draw_device->dev);
	PNG_close(&png);
	virt_delete_dev(draw_device);

	printf("main end\n\r");

	return 0;
}
